package eic.muckup.garden;

import java.util.ArrayList;


import android.app.ListActivity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class WateringHistoryActivity extends ListActivity {
	/**
	 * @see android.app.Activity#onCreate(Bundle)
	 */
	private WateringCalendarAdapter wca;
	private WateringCalendarClass mWateringCalendar;
	private ArrayList<WateringCalendarClass> mWateringCalenderList;
	private ListView mWateringCalendarListView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.water_history_listview);
		
		mWateringCalendarListView = getListView();
		mWateringCalendar = new WateringCalendarClass();
		
		mWateringCalenderList = new ArrayList<WateringCalendarClass>();
		
		setData(mWateringCalenderList);
		
		wca = new WateringCalendarAdapter(this, R.layout.water_calendar_list_row, mWateringCalenderList);
		mWateringCalendarListView.setAdapter(wca);
	}
	
	private void setData(ArrayList<WateringCalendarClass> list){
		WateringCalendarClass w = new WateringCalendarClass();
		w.setDate("Date:	26-05-2012");
		w.setWaterCalendarStartTime("Start time:	05.30");
		w.setWaterCalendarEndTime("End time:	06.00");
		list.add(w);
		
		w = new WateringCalendarClass();
		w.setDate("Date:	04-05-2012");
		w.setWaterCalendarStartTime("Start time:	23.30");
		w.setWaterCalendarEndTime("End time:	24.00");
		list.add(w);
		
		
		w = new WateringCalendarClass();
		w.setDate("Date:	26-04-2012");
		w.setWaterCalendarStartTime("Start time:	12.00");
		w.setWaterCalendarEndTime("End time:	12.30");
		list.add(w);
	}
	
	private class WateringCalendarAdapter extends ArrayAdapter<WateringCalendarClass>{
		private ArrayList<WateringCalendarClass> mItems;
		private Context mContext;
			
		public WateringCalendarAdapter(Context context, int textViewResourceId, 
				ArrayList<WateringCalendarClass> items){
			super(context, textViewResourceId, items);
			mItems = items;
			mContext = context;
		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent){
			View v = convertView;
			if(v == null){
				LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				v = vi.inflate(R.layout.water_calendar_list_row, null);
			}
			WateringCalendarClass WCC = mItems.get(position);
			if(WCC != null){
				TextView tt = (TextView) v.findViewById(R.id.water_startDate);
				if(tt != null){
					
					tt.setText(WCC.getWaterCalendarStartTime());
					tt.setTextColor(Color.GREEN);
				}
				TextView tv = (TextView) v.findViewById(R.id.water_StopDate);
				if(tv != null){
					tv.setText(WCC.getWaterCalendarEndTime());
					tv.setTextColor(Color.RED);
				}
				TextView tn = (TextView) v.findViewById(R.id.water_Name);
				if(tn != null)
				{
					tn.setText(WCC.getDate());
					
				}
			}
			return v;
		}
	}
}
